package com.lvmama.dashboard.model.page;

import java.io.Serializable;
import java.util.List;

/**
 * 分页实体
 * @author wxliyong
 */
public class PageResult<T> implements Serializable {
	private static final long serialVersionUID = 4131384386071752615L;
	private String message;
	private boolean success;
	private Exception exception;
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	public boolean isSuccess() {
		return success;
	}
	public void setSuccess(boolean success) {
		this.success = success;
	}
	public Exception getException() {
		return exception;
	}
	public void setException(Exception exception) {
		this.exception = exception;
	}
	/** 数据 */
	private List<T> list;
	/** 当前页码 */
	private int page;
	/** 每页条数 */
	private int pageSize;
	/** 总行数 */
	private long totalSize;
	public PageResult(int page, int pageSize, long totalSize) {
		this.page = page;
		this.pageSize = pageSize;
		this.totalSize = totalSize;
	}
	public PageResult(int page, int pageSize) {
		this(page, pageSize, 0L);
	}
	public PageResult(long totalSize) {
		this(1, 20, totalSize);
	}
	public PageResult() {
		this(1, 20, 0L);
	}
	public int getPage() {
		return page;
	}
	public int getPageStartRow() {
		return (page - 1) * pageSize + 1;
	}
	public int getPageEndRow() {
		return page * pageSize;
	}
	public int getTotalPage() {
		return (int) (totalSize/pageSize);
	}
	public boolean hasNextPage() {
		return getTotalPage() > getPage();
	}
	public boolean hasPreviousPage() {
		return getPage() > 0;
	}
	public int getPageSize() {
		return pageSize;
	}
	public long getTotalSize() {
		return totalSize;
	}
	public void setTotalSize(long totalSize) {
		this.totalSize = totalSize;
	}
	public List<T> getList() {
		return list;
	}
	public void setList(List<T> list) {
		this.list = list;
	}
}
